package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.VehicleParamMapper;
import com.molichuxing.services.infrastructure.dto.response.CarBaseConfDto;
import com.molichuxing.services.infrastructure.dto.response.VehicleModelParamDto;
import com.molichuxing.services.infrastructure.service.VehicleParamService;
import com.molichuxing.services.property.BaseCarModelParamEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * 车型 服务实现类
 * </p>
 * @author
 * @since 2019-08-12
 */
@Service("vehicleParamService")
public class VehicleParamServiceImpl implements VehicleParamService {

  @Autowired
  private VehicleParamMapper vehicleParamMapper;


  @Override
  public List<VehicleModelParamDto> getParamByModelId(Integer modelId, List<String> paramName, Integer paramBasic) {
    return Convert.toVehicleModelParamDto(vehicleParamMapper.getParamByModelId(modelId, paramName, paramBasic));
  }

  @Override
  public List<VehicleModelParamDto> findParamSort(Integer modelId, Integer paramBasic) {
    return Convert.toVehicleModelParamDto(vehicleParamMapper.findParamSort(modelId,paramBasic));
  }

  @Override
  public List<CarBaseConfDto> findCarModelParamByModelId(Integer modelId) {
    List<CarBaseConfDto>  dtoList = null;
    List<VehicleModelParamDto> list = findParamSort(modelId,null);
    if(null != list && list.size()>0) {
      dtoList= new ArrayList<CarBaseConfDto>();
      List<VehicleModelParamDto>  basics=new ArrayList<>();
      List<VehicleModelParamDto>  powerSyses=new ArrayList<>();
      List<VehicleModelParamDto>  chassisSyses=new ArrayList<>();
      List<VehicleModelParamDto>  controlSafetys=new ArrayList<>();
      List<VehicleModelParamDto>  facades=new ArrayList<>();
      List<VehicleModelParamDto>  interiors=new ArrayList<>();
      List<VehicleModelParamDto>  recreations=new ArrayList<>();
      for (VehicleModelParamDto modelParamResDto : list){
        if(modelParamResDto.getParamType()==BaseCarModelParamEnum.BASIC.getValue()) {
          basics.add(modelParamResDto);
        }else if(modelParamResDto.getParamType()==BaseCarModelParamEnum.POWER_SYS.getValue()) {
          powerSyses.add(modelParamResDto);
        }else if(modelParamResDto.getParamType()==BaseCarModelParamEnum.CHASSIS_SYS.getValue()) {
          chassisSyses.add(modelParamResDto);
        }else if(modelParamResDto.getParamType()==BaseCarModelParamEnum.CONTROL_SAFETY.getValue()) {
          controlSafetys.add(modelParamResDto);
        }else if(modelParamResDto.getParamType()==BaseCarModelParamEnum.WAI_GUAN.getValue()) {
          facades.add(modelParamResDto);
        }else if(modelParamResDto.getParamType()==BaseCarModelParamEnum.NEI_SHI.getValue()) {
          interiors.add(modelParamResDto);
        }else if(modelParamResDto.getParamType()==BaseCarModelParamEnum.YU_LE.getValue()) {
          recreations.add(modelParamResDto);
        }
      }
      CarBaseConfDto basic = new CarBaseConfDto();
      basic.setConfType(BaseCarModelParamEnum.BASIC.getValue());
      basic.setConfName(BaseCarModelParamEnum.BASIC.getName());
      basic.setCarModelParamList(basics);
      dtoList.add(basic);
      CarBaseConfDto powerSys = new CarBaseConfDto();
      powerSys.setConfType(BaseCarModelParamEnum.POWER_SYS.getValue());
      powerSys.setConfName(BaseCarModelParamEnum.POWER_SYS.getName());
      powerSys.setCarModelParamList(powerSyses);
      dtoList.add(powerSys);
      CarBaseConfDto chassisSys = new CarBaseConfDto();
      chassisSys.setConfType(BaseCarModelParamEnum.CHASSIS_SYS.getValue());
      chassisSys.setConfName(BaseCarModelParamEnum.CHASSIS_SYS.getName());
      chassisSys.setCarModelParamList(chassisSyses);
      dtoList.add(chassisSys);
      CarBaseConfDto controlSafety = new CarBaseConfDto();
      controlSafety.setConfType(BaseCarModelParamEnum.CONTROL_SAFETY.getValue());
      controlSafety.setConfName(BaseCarModelParamEnum.CONTROL_SAFETY.getName());
      controlSafety.setCarModelParamList(controlSafetys);
      dtoList.add(controlSafety);
      CarBaseConfDto facade = new CarBaseConfDto();
      facade.setConfType(BaseCarModelParamEnum.WAI_GUAN.getValue());
      facade.setConfName(BaseCarModelParamEnum.WAI_GUAN.getName());
      facade.setCarModelParamList(facades);
      dtoList.add(facade);
      CarBaseConfDto interior = new CarBaseConfDto();
      interior.setConfType(BaseCarModelParamEnum.NEI_SHI.getValue());
      interior.setConfName(BaseCarModelParamEnum.NEI_SHI.getName());
      interior.setCarModelParamList(interiors);
      dtoList.add(interior);
      CarBaseConfDto recreation = new CarBaseConfDto();
      recreation.setConfType(BaseCarModelParamEnum.YU_LE.getValue());
      recreation.setConfName(BaseCarModelParamEnum.YU_LE.getName());
      recreation.setCarModelParamList(recreations);
      dtoList.add(recreation);

    }
    return dtoList;
  }
}
